/**
 *
 */
package anyware.common.restlet;

import java.util.HashMap;
import java.util.Map;

import org.restlet.resource.Representation;
import org.restlet.resource.Variant;

/**
 * TODO: doc me
 *
 * @author keke<keke@codehaus.org>
 * @revision $Revision: 111 $
 * @version
 */
public class SimpleRepresentationHelper implements RepresentationHelper {
	private Map<String, RepresentationHandler>	handlers	= new HashMap<String, RepresentationHandler>();

	/**
	 * @return the handlers
	 */
	public Map<String, RepresentationHandler> getHandlers() {
		return handlers;
	}

	/**
	 * @param handlers
	 *            the handlers to set
	 */
	public void setHandlers(final Map<String, RepresentationHandler> handlers) {
		this.handlers = handlers;
	}

	public Object toEntity(final String name, final Representation rep) {
		final RepresentationHandler handler = handlers.get(name);
		return handler == null ? null : handler.toEntity(rep);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see anysware.restlet.RepresentationHelper#toRepresentation(java.lang.String,
	 *      java.lang.Object, org.restlet.resource.Variant)
	 */
	public Representation toRepresentation(final String name,
	        final Object entity, final Variant variant) {
		final RepresentationHandler handler = handlers.get(name);
		return handler == null ? null : handler.toRepresentation(entity,
		        variant);
	}

}
